var api = require('../../../../api.js');
var utils = require('../../../../utils.js');
var WxParse = require('../../../../wxParse/wxParse.js');

var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userimg:'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2124688991,875616927&fm=26&gp=0.jpg'
    },
    // 赠送好友
    to_friend:function(){
        let that = this;
        let friend_id = that.data.friend_id;
        console.log(friend_id + "======friend_id")
        let coupon_id = that.data.coupon_id;
        console.log(coupon_id + "==========coupon_id")
        app.request({
            url: api.casa.transfer,
            data: {
                coupon_id: coupon_id,
                other_user_id: friend_id
            },
            success: function (res) {
                
                if(res.code==0){
                    wx.redirectTo({
                        url: '/page/casa/pages/myself/myself',
                    })
                    wx.showToast({
                        title: res.msg,
                        icon: 'loading',
                        duration: 1500,
                        mask: true,
                    })
                }else {
                    wx.showToast({
                        title: res.msg,
                        icon: 'loading',
                        duration: 1500,
                        mask: true,
                    })
                }
             },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    have_name:function(e){
        let that = this;
        console.log(e.detail.value)
        let name = e.detail.value;
        that.setData({
            name:name
        })
    },
    // 查找好友
    search_friend:function(){
        let that =this;
        let name = that.data.name;
        app.request({
            url: api.casa.search_member,
            data: {
                name:name
            },
            success: function(res) {
                console.log(res)
                that.setData({
                    friend_list:res.data.list
                })
            },
        })
    },
    // 选择好友
    checked_frend:function(e){
        console.log(e.detail.value)
        let friend_id=e.detail.value;
        let that = this;
        that.setData({
            friend_id: friend_id
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let page = this;
        let coupon_id = options._id ;
        console.log(options)
        console.log(options._id )
        page.setData({
            coupon_id: coupon_id
        })

        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})